﻿/* Initialize */
jQuery(
  function ($) {
    $.Body = $('.ImagesArea');
    $.Window = $('.ImagesArea');
    $.Scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $.Body;
    $.Mobile = ($.Body.hasClass('webkit-mobile') || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))),
    $.Unsupported = $.Body.hasClass('unsupported-browser');
    $.Body.Keyboard()
    $('[data-controller]').Instantiate();
  }
);
/* ---------------------------------- */
/* Events */
(function($) {
  $.Events = {
     SECTION_ENTER: 'sectionEnter',
     SCROLL_TO: 'scrollTo',

     SCROLL: 'windowScroll',
     SCROLL_ENTER: 'windowScrollEnter',
     SCROLL_LEAVE: 'windwScrollLeave',

     KEY_UP: 'keyUp',
     KEY_DOWN: 'keyDown',
     KEY_LEFT: 'keyLeft',
     KEY_RIGHT: 'keyRight',
     KEY_ESC: 'keyEsc',
     KEY_SPACE: 'keySpace',

     PROOF_POINT: 'proofPointMore'

  } // Events

  $.Views = {
  } // Views
})(jQuery);
/* ---------------------------------- */
/* Auto Instantiate */
(function($) {
  $.fn.Instantiate = function(settings) {
    var config = {};
    if (settings) $.extend(config, settings);
      this.each(function() {
          var $self = $(this),
              $controller = $self.attr('data-controller');

          if ($self[$controller])
            $self[$controller]();
      });
  }
})(jQuery);
/* ---------------------------------- */
/* Shell */
(function($) {
  $.fn.SHELL = function(settings) {
    var config = {};
    if (settings) $.extend(config, settings);
      this.each(function() {
      });
      return this;
  }
})(jQuery);
/* ---------------------------------- */
/* Scrollable */
(function($) {
  $.fn.Scrollable = function(settings) {
     var config = { threshold: -100, offset_scroll: 6, offset_intertia: .15 };
     if (settings) $.extend(config, settings);	 
     this.each(function() {
        var $self = $(this),
            $id = $self.attr('id');
        config.threshold = 0
        if ($.Mobile || $.Unsupported) {
          $self.css({backgroundAttachment:'scroll'})
        }else{
        $.Window.bind('scroll',
            function(e){
			var fixWi = $('.mapIn').css('left') + " ";
              if ( $.inview($self,{threshold:config.threshold}) ) {
                if (!$self.hasClass('_active')){
                  $self.addClass('_active');
                  if (settings.is_nav)
                    $.Body.triggerHandler($.Events.SECTION_ENTER,$id);
                  $self.triggerHandler($.Events.SCROLL_ENTER);
                }
                _scroll_background();
                $self.triggerHandler($.Events.SCROLL,$.distancefromfold($self,{threshold:config.threshold}) - config.threshold)
              }else{
                if ($self.hasClass('_active')){
                  $self.removeClass('_active');
                  $self.triggerHandler($.Events.SCROLL_LEAVE);
                }
              }
            })
        }

        function _scroll_background() {
		  var fixWi = $('.mapIn').css('left') + " ";
          var _x = fixWi
          var _z = '0% '
          var bpos = _x + '0px';
		  //var bpos = _x + '73px';
		  //		var bpos2 = _z + (-($.distancefromfold($self,{threshold:config.threshold}) - config.threshold) * config.offset_intertia) + 'px';
          $self.css({'backgroundPosition':bpos})
        }
     });
    return this;
  } //Bloque

    $.fn.uno = function() {

     this.each(function() {

        var $self = $(this),
			$bg = $self.find('.bg'),
			$cont = $self.find('.cont01'),
			$cont2 = $self.find('.cont02'),
			$map = $self.find('.map01')
			_threshold = -100;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
			var fixWi = $('.mapIn').css('left') + " ";
		var imgH = $("#bloque-uno .bg3").css("background-size");
         var bpos = fixWi + ($.Window.height()-distance) + 'px';
         var contL = fixWi + ($.Window.height() - distance + 150) + 'px';
         var contL2 = fixWi + ($.Window.height()/4 - distance/4) + 'px';
         var contL2 = fixWi + ($.Window.height()/4 - distance/4) + 'px';
         var map01 = 301 + ($.Window.height() - distance) + 'px';
				
			   $bg.css({'backgroundPosition':bpos});
			   $cont.css({'backgroundPosition':contL});
			   $cont2.css({'backgroundPosition':contL2});
			  // $map.css({'top':map01});
        }
     });

    return this;

  } //uno

  $.fn.dos = function() {

     this.each(function() {

        var $self = $(this),
			$bg = $self.find('.bg'),
			$cont3 = $self.find('.cont03'),
			$cont4 = $self.find('.cont04'),
			$cont401 = $self.find('.cont0401'),
			$map02 = $self.find('.map02')
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
			//console.log(distance);
		   var fixWi = $('.mapIn').css('left') + " ";
           var bpos = fixWi + ($.Window.height()-distance) + 'px';
           var contL3 = fixWi + ($.Window.height() - distance/1.2) + 'px';
		   var contL4 = fixWi + ($.Window.height()/2 - distance/3) + 'px';
		   var contL401 = fixWi + ($.Window.height()-distance) + 'px';
		   var map02 = 250 + ($.Window.height() - distance) + 'px';
		   $bg.css({'backgroundPosition':bpos});
		   $cont3.css({'backgroundPosition':contL3});
		   $cont4.css({'backgroundPosition':contL4});
		   $cont401.css({'backgroundPosition':bpos});
		   //$map02.css({'top':map02});

        }


     });

    return this;

  } //dos

  $.fn.tres = function() {

     this.each(function() {

        var $self = $(this),
            $bg = $self.find('.bg'),
			$cont5 = $self.find('.cont05'),
			$cont6 = $self.find('.cont06'),
			$cont601 = $self.find('.cont0601'),
			$Sun = $self.find('.sun'),
			$map03 = $self.find('.map03')
			_threshold = -300;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
			//console.log(distance);
		   var fixWi = $('.mapIn').css('left') + " ";
           var bpos = fixWi + ($.Window.height()-distance) + 'px';
		   var contL5 = fixWi + ($.Window.height()/2 - distance/1.2) + 'px';
		   var contL6 = fixWi + ($.Window.height()/2 - distance/2.1) + 'px';
		   var Sun = fixWi + ($.Window.height()/2 - distance/2.3) + 'px';
		   var contL601 = fixWi + ($.Window.height()-distance) + 'px';
		   var map03 = 250 + ($.Window.height() - distance) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $cont5.css({'backgroundPosition':contL5});
		   $cont6.css({'backgroundPosition':contL6});
		   $Sun.css({'backgroundPosition':Sun});
		   $cont601.css({'backgroundPosition':contL601});
		   //$map03.css({'top':map03});

        }


     });

    return this;

  } //tres



  $.fn.cuatro = function() {

     this.each(function() {

        var $self = $(this),
            $bg = $self.find('.bg'),
            $cont7 = $self.find('.cont07'),
            $cont8 = $self.find('.cont08'),
            $cont801 = $self.find('.cont0801'),
            $Moon = $self.find('.moon'),
			$map04 = $self.find('.map04')
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
		   var fixWi = $('.mapIn').css('left') + " ";
           var bpos = fixWi + ($.Window.height()-distance) + 'px';
		   var contL7 = fixWi + ($.Window.height()/2 - distance/3) + 'px';
		   var contL8 = fixWi + ($.Window.height()/2 - distance/2.1) + 'px';
		   var contL801 = fixWi + ($.Window.height()-distance) + 'px';
		   var Moon = fixWi + ($.Window.height()/2 - distance/1.2) + 'px';
		   var map04 = 270 + ($.Window.height() - distance) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $cont7.css({'backgroundPosition':contL7});
		   $cont8.css({'backgroundPosition':contL8});
		   $cont801.css({'backgroundPosition':contL801});
		   $Moon.css({'backgroundPosition':Moon});
		   //$map04.css({'top':map04});

        }


     });

    return this;

  } //cuatro


  $.fn.cinco = function() {

     this.each(function() {

        var $self = $(this),
            $bg = $self.find('.bg'),
            $cont9 = $self.find('.cont09'),
            $cont10 = $self.find('.cont10'),
            $cont1001 = $self.find('.cont1001'),
            $Star = $self.find('.star'),
			$map05 = $self.find('.map05')
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
		   var fixWi = $('.mapIn').css('left') + " ";
           var bpos = fixWi + ($.Window.height()-distance) + 'px';
		   var contL9 = fixWi + ($.Window.height()/2 - distance/1.2) + 'px';
		   var contL10 = fixWi + ($.Window.height()/2 - distance/3) + 'px';
		   var contL1001 = fixWi + ($.Window.height()-distance) + 'px';
		   var Star = fixWi + ($.Window.height()/2 - distance/1.2) + 'px';
		   var map05 = 270 + ($.Window.height() - distance) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $cont9.css({'backgroundPosition':contL9});
		   $cont10.css({'backgroundPosition':contL10});
		   $cont1001.css({'backgroundPosition':contL1001});
		   $Star.css({'backgroundPosition':Star});
		   //$map05.css({'top':map05});

        }


     });

    return this;

  } //cinco


  $.fn.seis = function() {

     this.each(function() {

        var $self = $(this),
            $bg = $self.find('.bg'),
            $cont11 = $self.find('.cont11'),
            $cont12 = $self.find('.cont12'),
            $cont1201 = $self.find('.cont1201'),
			$map06 = $self.find('.map06')
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
           var fixWi = $('.mapIn').css('left') + " ";
           var bpos = fixWi + ($.Window.height()-distance) + 'px';
		   var contL11 = fixWi + ($.Window.height()/2 - distance/3) + 'px';
		   var contL12 = fixWi + ($.Window.height()/2 - distance/1.2) + 'px';
		   var contL1201 = fixWi + ($.Window.height()-distance) + 'px';
		   var map06 = 210 + ($.Window.height() - distance) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $cont11.css({'backgroundPosition':contL11});
		   $cont12.css({'backgroundPosition':contL12});
		   $cont1201.css({'backgroundPosition':contL1201});
		   //$map06.css({'top':map06});

        }


     });

    return this;

  } //seis


  $.fn.siete = function() {

     this.each(function() {

        var $self = $(this),
           $bg = $self.find('.bg'),
           $cont13 = $self.find('.cont13'),
           $cont1301 = $self.find('.cont1301'),
		   $map07 = $self.find('.map07')
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {
		   var fixWi = $('.mapIn').css('left') + " ";
           var bpos = fixWi + ($.Window.height()-distance) + 'px';
		   var contL13 = fixWi + ($.Window.height()/2 - distance/1.2) + 'px';
		   var cont1301 = ($.Window.height() - distance) + 'px';
		   var map07 = 250 + ($.Window.height() - distance) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $cont13.css({'backgroundPosition':contL13});
		   $cont1301.css({'top':cont1301});
		   //$map07.css({'top':map07});

        }


     });

    return this;

  } //siete

   $.fn.ocho = function() {

     this.each(function() {

        var $self = $(this),
            $id = $self.attr('id'),
            $bg = $self.find('.bg'),
			$bg2 = $self.find('.bg2'),
			$bg3 = $self.find('.bg3'),
			$bg5 = $self.find('.bg5'),
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {

           var bpos = '95% ' + (130+$.Window.height()/2-distance/3) + 'px';
		       bpos2 = '50% ' + (0+$.Window.height()/2-distance/3) + 'px';
			   bpos3 = '50% ' + (470+$.Window.height()/2-distance/3) + 'px';
			   bpos5 = '10% ' + (80+$.Window.height()/2-distance/3) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $bg2.css({'backgroundPosition':bpos2});
		   $bg3.css({'backgroundPosition':bpos3});
		   $bg5.css({'backgroundPosition':bpos5});

        }


     });

    return this;

  } //ocho



  $.fn.nueve = function() {
   this.each(function() {

        var $self = $(this),
            $id = $self.attr('id'),
            $bg = $self.find('.bg'),
			$bg2 = $self.find('.bg2'),
			$bg3 = $self.find('.bg3'),
			$bg4 = $self.find('.bg4'),
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {

           var bpos = '96% ' + (20+$.Window.height()/2-distance/2.5) + 'px';
		       bpos2 = '20% ' + (340+$.Window.height()/2-distance/2) + 'px';
			   bpos3 = '96% ' + (-150+$.Window.height()/2-distance/5) + 'px';
			   bpos4 = '96% ' + (-150+$.Window.height()/2-distance/4) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $bg2.css({'backgroundPosition':bpos2});
		   $bg3.css({'backgroundPosition':bpos3});
		   $bg4.css({'backgroundPosition':bpos4});


        }


     });

    return this;

  } //nueve

    $.fn.diez = function() {
   this.each(function() {

        var $self = $(this),
            $id = $self.attr('id'),
            $bg = $self.find('.bg'),
			$bg2 = $self.find('.bg2'),
			$bg3 = $self.find('.bg3'),
			$bg5 = $self.find('.bg5'),
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {

           var bpos = '95% ' + (130+$.Window.height()/2-distance/3) + 'px';
		       bpos2 = '50% ' + (0+$.Window.height()/2-distance/3) + 'px';
			   bpos3 = '50% ' + (470+$.Window.height()/2-distance/3) + 'px';
			   bpos5 = '10% ' + (80+$.Window.height()/2-distance/3) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $bg2.css({'backgroundPosition':bpos2});
		   $bg3.css({'backgroundPosition':bpos3});
		   $bg5.css({'backgroundPosition':bpos5});

        }


     });

    return this;

  } //diez

     $.fn.footer = function() {
   this.each(function() {

        var $self = $(this),
            $id = $self.attr('id'),
            $bg = $self.find('.bg'),
			$bg2 = $self.find('.bg2'),
			$bg3 = $self.find('.bg3'),
			$bg5 = $self.find('.bg5'),
			_threshold = -200;

        $self
          .Scrollable({threshold: _threshold,is_nav:true})
          .bind($.Events.SCROLL,on_scroll)

        function on_scroll(e,distance) {

           var bpos = '50% ' + (130+$.Window.height()/2-distance/3) + 'px';
		       bpos2 = '50% ' + (0+$.Window.height()/2-distance/3) + 'px';
			   bpos3 = '50% ' + (470+$.Window.height()/2-distance/3) + 'px';
			   bpos5 = '10% ' + (80+$.Window.height()/2-distance/3) + 'px';

           $bg.css({'backgroundPosition':bpos});
		   $bg2.css({'backgroundPosition':bpos2});
		   $bg3.css({'backgroundPosition':bpos3});
		   $bg5.css({'backgroundPosition':bpos5});

        }


     });

    return this;

  } //footer

})(jQuery);

/* SiteScroll */
(function($) {
   $.fn.SiteScroll = function() {
     this.each(function() {
        var $self = $(this);
        $.Body.bind($.Events.SCROLL_TO,
            function(e,id){
              var $element = $('#'+id),
                  $header = $element.find('header'),
                  _align = $element.attr('data-align'),
                  _offset = $element.attr('data-scrolloffset') ? parseInt($element.attr('data-scrolloffset')) : 50,
                  _top = $element.offset().top;

              if ($header.length>0 && _align!="top") {
                  _top = $header.offset().top  + $header.height()/2 - $.Window.height()/2;
                  if (_top > $header.offset().top)
                    _top = $header.offset().top - 50
              }

              if (_align=="center" && $element.height()>$.Window.height()) {
                _top = $element.offset().top + ($element.height()-$.Window.height())/2
              }

              $.Scroll.stop().animate({ 'scrollTop': _top }, 800, 'easeInOutQuart')
            })
     });
    return this;
  }
})(jQuery);
/* ---------------------------------- */
/* Keyboard */
(function($) {
  $.fn.Keyboard = function(settings) {
		var config = {};
    if (settings) $.extend(config, settings);
      this.each(function() {
        var $self = $(this);
        $(document).bind('keydown',on_keydown);

        function on_keydown(e) {
          var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
          switch(key) {
             case 27: //escape
              $.Body.triggerHandler($.Events.KEY_ESC); break;
             case 32: //space
              $.Body.triggerHandler($.Events.KEY_SPACE); break;
             case 38: //top
              $.Body.triggerHandler($.Events.KEY_UP); break;
             case 39: //right
              $.Body.triggerHandler($.Events.KEY_RIGHT);
              e.preventDefault(); break;
             case 40: ///bottom
              $.Body.triggerHandler($.Events.KEY_DOWN); break;
             case 37: //left
              $.Body.triggerHandler($.Events.KEY_LEFT); break;
          }//switch
        }//keydown
      });
      return this;
  }
})(jQuery);
/* ---------------------------------- */
/* Worker */
(function($) {
    $.distancefromfold = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).height() + $(window).scrollTop();
        } else {
            var fold = $(settings.container).offset().top + $(settings.container).height();
        }
        return (fold + settings.threshold) - $element.offset().top ;
    };

    $.belowthefold = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).height() + $(window).scrollTop();
        } else {
            var fold = $(settings.container).offset().top + $(settings.container).height();
        }
        return fold <= $element.offset().top - settings.threshold;
    };

    $.rightoffold = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).width() + $(window).scrollLeft();
        } else {
            var fold = $(settings.container).offset().left + $(settings.container).width();
        }
        return fold <= $element.offset().left - settings.threshold;
    };

    $.abovethetop = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).scrollTop();
        } else {
            var fold = $(settings.container).offset().top;
        }
        return fold >= $element.offset().top + settings.threshold  + $element.height();
    };

    $.leftofbegin = function($element, settings) {
        if (settings.container === undefined || settings.container === window) {
            var fold = $(window).scrollLeft();
        } else {
            var fold = $(settings.container).offset().left;
        }
        return fold >= $element.offset().left + settings.threshold + $element.width();
    };

    $.inview = function($element, settings) {
        return ($.abovethetop($element,settings)!=true && $.belowthefold($element,settings)!=true)
    };


    $.extend($.expr[':'], {
        "below-the-fold" : "$.belowthefold(a, {threshold : 0, container: window})",
        "above-the-fold" : "!$.belowthefold(a, {threshold : 0, container: window})",
        "right-of-fold"  : "$.rightoffold(a, {threshold : 0, container: window})",
        "left-of-fold"   : "!$.rightoffold(a, {threshold : 0, container: window})"
    });
})(jQuery);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            